package andris.android.mobilarena.widget;

import andris.android.mobilarena.MobilarenaApplication;
import andris.android.mobilarena.R;
import andris.android.mobilarena.provider.MainListAdapter;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class MainListFragment extends ListFragment {

	private MainListAdapter mAdapter;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		mAdapter = new MainListAdapter(getActivity(), MobilarenaApplication.articles.getArticles());
		setListAdapter(mAdapter);

		getListView().setOnItemClickListener(mOnItemClickListener);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.main_fragment, null);
	}

	private OnItemClickListener mOnItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			Toast.makeText(getActivity(), MobilarenaApplication.articles.getArticles().get(arg2).getTitle(), Toast.LENGTH_SHORT).show();
		}
	};

}